
#include "stdafx.h"
#include "tvideoplayer.h"
#include "tmediasourcefilter.h"
#include "include/tevent.h"
#include "tappcore.h"
#include "tmediasource.h"

TAppCore::TAppCore()
{
	m_player = new TVideoPlayer;
	m_source = new TMediaSource;
}

TAppCore::~TAppCore()
{
	delete m_player;
	delete m_source;
}

HRESULT TAppCore::HandleEvent(TEvent * e) 
{
	return S_OK;
}

HRESULT TAppCore::SetDisplayWindow(HWND hWnd)
{
	m_source->setFilePath("F:\\b.avi");
	MprMediaType mt;
	CMediaType mediaType;
	GetMediaType(m_source, mt, mediaType);

	m_player->SetMediaSource(m_source, &mediaType);
	m_player->SetDisplayWindow(hWnd);
	m_player->Play();
	return S_FALSE;
}

void TAppCore::Destroy()
{
	delete this;
}


bool TAppCore::GetMediaType(TMediaSource *source, MprMediaType &mt, CMediaType &mediaType)
{
	unsigned char head[MprMediaHeadBytes];
	source->seek(0);
	if(MprMediaHeadBytes != source->read(head, MprMediaHeadBytes))
		return false;

	mediaType.majortype = MEDIATYPE_Stream;
	mediaType.subtype = MEDIASUBTYPE_NULL;
	GUID Guid;
	if(TMeadiaTypeHelper::GetMediaType(head, mt, Guid))
	{
		mediaType.subtype = Guid;
		return true;
	}
	return false;
}